package com.richfit.cuba.web.config.properties;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

public class MyLocalResolver implements LocaleResolver {

	private final String param = "lang";
	@Override
	public Locale resolveLocale(HttpServletRequest request) {
		String lang = request.getParameter(param);
        Locale locale = Locale.getDefault();
        if (StringUtils.isNotBlank(lang)) {
            String[] split = lang.split("_");
            locale = new Locale(split[0],split[1]);
        }
        return locale;
	}

	@Override
	public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

	}

}
